﻿using System.Windows.Forms;
using StockLib;
using System;
using System.Text.RegularExpressions;

namespace StockUI
{
    public partial class FormMain
    {
        // 处理快捷键
        protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
        {
            //Trace.WriteLine("Main.ProcessCmdKey " + keyData);

            switch (keyData)
            {
                case Keys.Escape:   // 后退
                    FindFormChild("Report");
                    return true;

                case Keys.F6:       // 自选股
                    string blockLabel = StockBlockGroupCustom.Instance.ZXGBlock.Name;
                    string blockId = StockBlockGroupCustom.Instance.ZXGBlock.BlockId;
                    CheckBlockMenu(blockId);
                    SendMessage(FindFormChild("Report"), new FormNotifyMessage("Report.Show", blockLabel, blockId));
                    return true;

                case Keys.F10:      // 基本资料
                    SendMessage(FindFormChild("Base"), new FormNotifyMessage("Base.Show", StockContainer.Instance.CurrentStock));
                    return true;

                case Keys.Control | Keys.S:     // 选股系统
                    new DialogToolChoose().ShowDialog(this);
                    return true;

                case Keys.Control | Keys.J:     // 预警系统
                    new DialogToolAlarm().ShowDialog(this);
                    return true;

                case Keys.Control | Keys.F:     // 公式管理器
                    new DialogToolFormula().ShowDialog(this);
                    return true;

                case Keys.Control | Keys.D:     // 系统设置
                    new DialogOptionSystem().ShowDialog(this);
                    return true;

                case Keys.Control | Keys.B:     // 板块设置
                    new DialogOptionBlock().ShowDialog(this);
                    return true;

                case Keys.Control | Keys.T:     // 标签设置
                    new DialogOptionTab().ShowDialog(this);
                    return true;

                case Keys.Control | Keys.R:     // 所属板块
                    if (StockContainer.Instance.CurrentStock != null)
                    {
                        new DialogStockBlockList().ShowDialog(this);
                    }
                    return true;

                case Keys.Control | Keys.Z:     // 加入板块
                    if (StockContainer.Instance.CurrentStock != null)
                    {
                        new DialogStockBlockPut().ShowDialog(this);
                    }
                    return true;

                case Keys.Alt | Keys.Z:         // 加入自选股
                    if (StockContainer.Instance.CurrentStock != null)
                    {
                        if (!StockBlockGroupCustom.Instance.ZXGBlock.ContainsKey(StockContainer.Instance.CurrentStock.CodeKey))
                        {
                            StockBlockGroupCustom.Instance.ZXGBlock.Add(StockContainer.Instance.CurrentStock.CodeKey, StockContainer.Instance.CurrentStock);
                            StockBlockGroupCustom.Instance.ZXGBlock.StockNumber = StockBlockGroupCustom.Instance.ZXGBlock.Count;
                        }
                    }
                    return true;
            }

            return base.ProcessCmdKey(ref msg, keyData);
        }

        // 处理通知消息
        protected override void ProcessNotifyMessage(FormNotifyMessage msg)
        {
            switch (msg.Message)
            {
                //行情子窗口更改了板块
                case "Main.ChangeBlock":
                    CheckBlockMenu(msg.Param1.ToString());
                    break;
            }
        }
    }
}
